/** Class Name: OORTelesalesSplitQuota 
 * Author: Accenture
 * Date: 3-March-2012
 * Requirement/Project Name: OOR Telesales
 * Requirement Description:  Test class for OORTelesalesUpdateLeadOwner
 * bhumika udani    23rd May 2012    v1.1      Fixed the deploy failure, insert u1 
 **/
 
@istest(seealldata=true)
private class OORTelesalesSplitQuotaTest 
{
    
    
    /**
     *  Test method 
     */  
    static testMethod void testsplitquota(){
    
      Profile p = [select id from profile where name='System Administrator'];           
      User u1 = new User(alias = 'tsplit', email='sysadminOpty@accenture.com',emailencodingkey='UTF-8', lastname='TestUserSplit',firstname='SystemTestOpty3', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testSplitOppty1@testorg.com',SFA_Office__c='BLT');
      
      insert u1;
      
      Opportunity oppty= New Opportunity();
      oppty.Name='TestOppty'; 
      //oppty.AccountId = testAcc.Id; 
       oppty.StageName ='Signed Contract'; 
       oppty.CloseDate= Date.Today();
       oppty.Opportunity_Type__c='Digital Express';  
       oppty.RecordtypeId = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Renewals'); 
       oppty.Booked_Date__c= Date.Today();
       System.debug('Oppty Booked Date'+ oppty.Booked_Date__c);
       oppty.Ext_Primary_Owner__c=u1.Id;      
       Insert oppty;
             
       Opportunity_Split__c  opptysplit = New Opportunity_Split__c ();
       opptysplit.opportunity__c=oppty.Id;
       //opptysplit.opportunity__r.Booked_Date__c=Date.Today(); 
       opptysplit.Owner_ID__c=u1.Id;
       //opptysplit.Booked_Date__c=oppty.Booked_Date__c;
       Insert opptysplit;

       List<Opportunity_Split__c> opList=[select opportunity__c ,Booked_Date__c from  Opportunity_Split__c where id=:opptysplit.id];
      
      System.debug('This is OpptyList'  + opList);
      
       QuotaManagement__c quotaManObj = new QuotaManagement__c();
       quotaManObj.MC__c = u1.Id;
       quotaManObj.QuotaDate__c= Date.Today();
      
       Insert quotaManObj;
      
       opptysplit.QuotaManagement__c= quotaManObj.id;
      
       update opptysplit;          
    }
    
}